<?
layout("/inc/layout.html",{title:sysTitle}){
?>
<style>
    	.tapqh{
    		height:35px;
    		margin:0px;
    		margin-top:5px;
    		padding:0px;
    		border-bottom:3px solid #d74b47;
    	}
    	.tapqh li{
    		float:left;
    		list-style: none;
    		line-height:33px;
    	}
    	.tapqh li a{
    		display:inline-block;
    		padding: 0px 15px;
    		font-size: 16px;
    		color: #333;
    		text-decoration: none;
    	}
    	.tapqh li a:hover{
    		color: #d74b47;
    		background-color: transparent;
    	}
    	.tapqh li a.active{
    		background-color:#d74b47;
    		color:#ffffff;
    	}
    </style>
<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">知识词表管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>知识词表管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">模板管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">
	<!-- 知识分类s -->
		<div class="panel panel-white">
			<div class="panel-heading">
				词表分类：
			</div>
			<div class="row">
				<div  class="col-md-12" style="width: 100%; " >
					<ul class="tapqh js-tapqh" id="classesList">
								
					</ul>
				</div>
		  </div>
				
				<div class="tb-group-actions" style="width: 98%;height: 35px;margin: 10px auto;">
					<button type="button" onclick="addMenu('0')" style="float: right;" class="btn btn-green btn-square" id="savejiedian">新增</button>
				</div>
				<div class="tb-group-actions" style="width: 98%;margin: 0 auto;">
				<table  class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
					<thead>
						<tr>
							<th width="50px"  style="text-align:center;white-space:nowrap;">序号</th>
							<th style="white-space:nowrap;">关系中文名称</th>
							<th style="white-space:nowrap;">关系英文名称</th>
							<th style="white-space:nowrap;">关系描述</th>
							<th style="white-space:nowrap;">排序</th>
							<th style="white-space:nowrap;">可操作</th>
						</tr>
					</thead>
					<tbody id="wordRelationLieBiao">
					
					</tbody>
				</table>
				</div>
			<div id="page2" style="text-align: center; margin-top: 10px; margin-bottom: 15px;"></div>
		<!--END CONTENT-->
	</div>
</div>
</div>
<?} ?>
<script>
	var module;
	var addUpId;
	var curr;
	$(function() {
		queryRoles();
	});
	
	function getModule() {
		return module;
	}
	function getCurr() {
		return curr;
	}
	function getAddUpId() {
		return addUpId;
	}
	//查询分类
	function queryRoles() {
		$.ajax({
			type : "post",
			url : "relationQueryWordModule.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(data) {
				var src='';
				for ( var i = 0; i < data.length; i++) {
					if(i == 0){
						src +='<li><a href="JavaScript:;" class="active" data-value="'+data[i].id+'">'+data[i].name+'</a></li>';
					}else{
						src +='<li><a href="JavaScript:;" data-value="'+data[i].id+'">'+data[i].name+'</a></li>';
					}
				}
				$("#classesList").html(src);
				queryWordRelation(1);	
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	$(document).on('click','.js-tapqh li a',function(){
		$(this).addClass('active').parent().siblings().find('a').removeClass('active');
		queryWordRelation(1);
	});
	//分类查询用户
	function queryWordRelation(curr){
		var classesId =$(".js-tapqh .active").data("value");
		$.ajax({
			type : "post",
			url : "getWordRelationList.do",
			data : {
				"id" : classesId,
				"page" : curr || 1,
			},
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(data) {
				var src='';
				for ( var i = 0; i < data[0].data.length; i++) {
					src += "<tr><td>"
						+ (i + 1)
						+ "</td><td> "
						+ data[0].data[i].nameZh
						+ "</td><td>"
						+ data[0].data[i].nameEn
						+ "</td><td>"
						+ data[0].data[i].description
						+ "</td><td>"
						+ data[0].data[i].sort
						+ "</td><td>"
						+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"addMenu('"
						+ data[0].data[i].id
						+ "')\">"
						+ "编辑"
						+ "</button>&nbsp;"
						+ "<button type=\"button\" class=\"btn btn-default btn-xs\" onclick=\"deleteMenu('"
						+ data[0].data[i].id
						+ "')\">删除</button>"
						+ "</td></tr>";
				}
				$("#wordRelationLieBiao").html(src);
				laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : data[0].count, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr : curr || 1,
					last: data[0].count,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							curr = obj.curr;
							queryWordRelation(obj.curr);
						}
					}
				});
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	
	//新增
	function addMenu(addorUp) {
		addUpId = addorUp;
		module =$(".js-tapqh .active").data("value");
		layer.open({
			type : 2,
			area : [ '500px', '450px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title : "添加模板",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [ "word-relation-add-upload.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	};
	//删除
	function deleteMenu(delId) {
		if (delId == null) {
			layer.msg('请选择要删除模板！');
		} else {
			if (confirm("是否确认删除！！")) {
				$.ajax({
					type : "post",
					url : "deleteWordRelation.do",
					data : {
						"id" : delId
					},
					dataType : "json",
					beforeSend : function(XMLHttpRequest) {
					},
					success : function(data) {
						queryWordRelation(curr);
						if(data[0].data == 'yes'){
							layer.msg('删除成功！');
						}else{
							layer.msg('删除失败！');
						}
					},
				});
			}
		}
	}
</script>